package com.github.llyb120.calengine.method;

import com.github.llyb120.calengine.entity.ScopeData;
import com.github.llyb120.calengine.rule.DatasetWrapper;
import com.github.llyb120.calengine.rule.DatasourceWrapper;
import com.github.llyb120.calengine.rule.RuleEngine;
import org.beetl.sql.core.SQLManager;

import java.util.List;

public class FromScope extends AbstractScriptFunc {


    public FromScope(RuleEngine ruleEngine) {
        super(ruleEngine);
    }

    @Override
    public Object call(Object... args) {
        String name = (String) args[0];
        DatasetWrapper dataset = getRuleEngine().getDataset(name);
        if (dataset == null) {
            return null;
        }
        DatasourceWrapper datasource = getRuleEngine().getDatasource(dataset.getScope().getUse());
        SQLManager sqlmanager = datasource.getSqlManager();
        List<ScopeData> scope = dataset.calculateScope();
        return scope;
    }


}
